package com.bh.web.controller.wms;

import com.bh.common.annotation.Log;
import com.bh.common.core.controller.BaseController;
import com.bh.common.core.domain.AjaxResult;
import com.bh.common.core.page.TableDataInfo;
import com.bh.common.enums.BusinessType;
import com.bh.common.utils.poi.ExcelUtil;
import com.bh.wms.domain.WmsInventoryLog;
import com.bh.wms.service.IWmsInventoryLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 库存流水接口
 *
 * @author GPT
 */
@Api(tags = "库存流水")
@RestController
@RequestMapping("/wms/inventory-log")
public class WmsInventoryLogController extends BaseController {

    @Autowired
    private IWmsInventoryLogService inventoryLogService;

    @ApiOperation("分页查询库存流水")
    @PreAuthorize("@ss.hasPermi('wms:inventorylog:list')")
    @GetMapping("/list")
    public TableDataInfo list(WmsInventoryLog query) {
        startPage();
        List<WmsInventoryLog> list = inventoryLogService.selectWmsInventoryLogList(query);
        return getDataTable(list);
    }

    @ApiOperation("导出库存流水")
    @PreAuthorize("@ss.hasPermi('wms:inventorylog:export')")
    @Log(title = "库存流水", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsInventoryLog query) {
        List<WmsInventoryLog> list = inventoryLogService.selectWmsInventoryLogList(query);
        ExcelUtil<WmsInventoryLog> util = new ExcelUtil<>(WmsInventoryLog.class);
        util.exportExcel(response, list, "库存流水数据");
    }

    @ApiOperation("获取库存流水详情")
    @PreAuthorize("@ss.hasPermi('wms:inventorylog:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return success(inventoryLogService.selectWmsInventoryLogById(id));
    }
}

